<template>
    <div class="topNav">
        <div class="topLeft">
            <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-liebiao"></use>
        </svg>
        </div>
        <div class="topCenter">
            <span :class="{active: index == currentIndex}" @click="btnActive(index, item.route)" v-for="(item, index) in list" :key="index">{{item.name}}</span>
        </div>
        <div class="topRight">
            <svg class="icon search" aria-hidden="true">
            <use xlink:href="#icon-search"></use>
        </svg>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            list: [
                {name: '我的', route: '/mine'},
                {name: '发现', route: '/'},
                {name: '云村', route: '/yuncun'},
                {name: '视频', route: '/video'},
            ],
            currentIndex: 1,
        }
    },
    methods: {
        btnActive(index, router){
            // 逻辑，就是点击哪个哪个激活，首先先全部为flase，然后设置点击的为true
            this.currentIndex = index;
            // 路由跳转
            this.$router.push(router)
        }
    }
}
</script>

<style lang="less" scoped>
.topNav {
    // background-color: pink;
    width: 7.5rem;
    height: 1rem;
    display: flex;
    justify-content: space-between;
    padding: 0 0.2rem;
    // line-height: 1rem;
    align-items: center;
    .icon{
        width: 0.5rem;
        height: 0.5rem;
    }
    .search{
        width: 0.45rem;
        height: 0.45rem;
    }
    .topCenter{
        width: 4.5rem;
        display: flex;
        justify-content: space-around;
        .active{
            font-weight: 900;
        }
    }
}
</style>